package com.dins.elashutina.parser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ekaterina.lashutina
 * Date: 05.09.13
 * Time: 10:11
 */
public class Node {
    private String name;
    private String path;
    private List<String> value;
    private List<Node> children = new ArrayList<Node>();
    private Node parent;
    private boolean wasIterated = false;
    private int currentLevel;

    public Node(String name, String path, List<String> value, Node parent) {
        this.name = name;
        this.path = path;
        this.value = value;
        this.parent = parent;
        if (parent == null) {
            currentLevel = 0;
        } else {
            currentLevel = parent.getCurrentLevel() + 1;
        }
    }

    public String getName() {
        return name;
    }

    public String getPath() {
        return path;
    }

    public List<String> getValues() {
        return value;
    }

    public void setValues(List<String> value) {
        this.value = value;
    }

    public String getValue(int i) {
        return value.get(i);
    }

    public List<Node> getChildren() {
        return children;
    }

    public Node getParent() {
        return parent;
    }

    public void addChild(Node child) {
        children.add(child);
    }

//    public void setParent(Node parent) {
//        this.parent = parent;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Node node = (Node) o;

        if (!name.equals(node.name)) return false;
        if (!parent.equals(node.parent)) return false;
        if (!path.equals(node.path)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + path.hashCode();
        result = 31 * result + parent.hashCode();
        return result;
    }

    public void setIterated(boolean wasIterated) {
        this.wasIterated = wasIterated;
    }

    public boolean wasIterated() {
        return wasIterated;
    }

    public int getCurrentLevel() {
        return currentLevel;
    }
}
